home *** CD-ROM | disk | FTP | other *** search
- /* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is Forecastfox.
- *
- * The Initial Developer of the Original Code is
- * Jon Stritar <jstritar@MIT.EDU>.
- * Portions created by the Initial Developer are Copyright (C) 2005
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- * Jon Stritar <jstritar@MIT.EDU>
- * Richard Klein <richwklein@mchsi.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
- const MANAGER_CLASS_ID = Components.ID("{5158b980-0a0e-11da-8cd6-0800200c9a66}");
- const MANAGER_CLASS_NAME = "Forecastfox Icon Manager Component";
- const MANAGER_CONTRACT_ID = "@ensolis.com/forecastfox/icon-manager;1";
- const INSTALLER_CLASS_ID = Components.ID("{f81ad500-24cb-11da-8cd6-0800200c9a66}");
- const INSTALLER_CLASS_NAME = "Forecastfox Icon Pack Installer";
- const INSTALLER_CONTRACT_ID = "@ensolis.com/forecastfox/icon-installer;1";
-
- const IM_PREFIX = "http://www.ensolis.com/2005/icon-manager#";
- const ICON_PREFIX = "http://www.ensolis.com/2005/icon-pack/";
- const ICONS_ROOT = "urn:ensolis:icon-packs:root";
- const ffIIconManager = Components.interfaces.ffIIconManager;
- const ffIError = Components.interfaces.ffIError;
- const ffIDisk = Components.interfaces.ffIDisk;
- const nsIFile = Components.interfaces.nsIFile;
-
- const REQUIRED_PACK_FILES = ["pack.rdf", "small/01.png", "small/02.png", "small/03.png", "small/04.png",
- "small/05.png", "small/06.png", "small/07.png", "small/08.png", "small/11.png", "small/12.png", "small/13.png", "small/14.png", "small/15.png",
- "small/16.png", "small/17.png", "small/18.png", "small/19.png", "small/20.png", "small/21.png", "small/22.png", "small/23.png", "small/24.png",
- "small/25.png", "small/26.png", "small/29.png", "small/30.png", "small/31.png", "small/32.png", "small/33.png", "small/34.png", "small/35.png",
- "small/36.png", "small/37.png", "small/38.png", "small/39.png", "small/40.png", "small/41.png", "small/42.png", "small/43.png", "small/44.png",
- "small/radar.png", "small/swa.png", "large/01.png", "large/02.png", "large/03.png", "large/04.png", "large/05.png", "large/06.png", "large/07.png",
- "large/08.png", "large/11.png", "large/12.png", "large/13.png", "large/14.png", "large/15.png", "large/16.png", "large/17.png", "large/18.png",
- "large/19.png", "large/20.png", "large/21.png", "large/22.png", "large/23.png", "large/24.png", "large/25.png", "large/26.png", "large/29.png",
- "large/30.png", "large/31.png", "large/32.png", "large/33.png", "large/34.png", "large/35.png", "large/36.png", "large/37.png", "large/38.png",
- "large/39.png", "large/40.png", "large/41.png", "large/42.png", "large/43.png", "large/44.png", "large/swa.png"];
-
- const REQUIRED_ICON_PROPS = ["id", "name", "version", "website", "author", "target", "smallWidth", "smallHeight", "largeWidth", "largeHeight"];
-
- function ffIconManager() {};
-
- ffIconManager.prototype = {
- _manager: null,
- _rdfserv: null,
- _ds: null,
- _bundle: null,
- _obs: null,
- _current: null,
-
- get datasource() {
- if (!this._ds)
- this._getRdf(false);
-
- return this._ds;
- },
-
- get current() { return this._current; },
-
- start: function()
- {
- this._manager = Components.classes["@ensolis.com/forecastfox/manager;1"].getService(Components.interfaces.ffIManager);
- this._rdfserv = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService);
- var sbs = Components.classes["@mozilla.org/intl/stringbundle;1"].getService(Components.interfaces.nsIStringBundleService);
- this._bundle = sbs.createBundle("chrome://forecastfox/locale/forecastfox.properties");
- this._obs = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
-
- this._removeOldFiles();
-
- // get the rdf service and datasource
- this._getRdf(false);
- this.setCurrent(this._manager.getUTFPref("icons.current"));
- },
-
- stop: function()
- {
- this._manager = null;
- this._rdfserv = null;
- this._ds = null;
- this._bundle = null;
- this._obs = null;
- },
-
- getItemList: function(aCount)
- {
- var items = [];
-
- // get the container for all the icons
- var root = ICONS_ROOT;
- var ctr = Components.classes["@mozilla.org/rdf/container;1"].createInstance(Components.interfaces.nsIRDFContainer);
- ctr.Init(this._ds, this._rdfserv.GetResource(root));
-
- //loop through and get each item
- var els = ctr.GetElements();
- while (els.hasMoreElements()) {
- var el = els.getNext().QueryInterface(Components.interfaces.nsIRDFResource);
- items.push(this.getItemForId(this._stripIconPrefix(el.Value)));
- };
-
- // sort the items by name
- var component = this;
- items.sort(component._sortItems);
-
- aCount.value = items.length;
- return items;
- },
-
- getItemForId: function( aId )
- {
- if (this._hasIconPack(aId)) {
- return this._createIconPack(aId);
- } else {
- this._manager.disk.recordMessage("ERROR: Could not retrieve icon pack "+aId+", reverting to default.\n");
- this._manager.setUTFPref("icons.current", "default");
- return this.getDefaultItem();
- };
- },
-
- getDefaultItem: function()
- {
- try {
- return this._createIconPack("default");
- } catch (e) {
- this._getRdf(true);
- this._manager.disk.recordError("ERROR: Failure in retrieving default icon pack. Reverting to default icon rdf.", e);
- return Components.classes["@ensolis.com/forecastfox/icon-pack;1"].createInstance(Components.interfaces.ffIIconPack);
- };
- },
-
- installItem: function( aFile )
- {
- // Create and initialize the installer.
- var installer = Components.classes["@ensolis.com/forecastfox/icon-installer;1"].createInstance(Components.interfaces.ffIIconInstaller);
- installer.init(aFile);
-
- // Validate the file...
- var err = installer.validate();
- if (err.severity != ffIError.SEVERITY_INFO)
- this._manager.disk.recordMessage("ERROR: " + err.toString());
-
- //not validated
- if (!installer.validated) {
- installer.destroy();
- return false;
- };
-
- //try install
- var rv = false;
- try {
- rv = installer.performInstall();
- } catch(e) {
- var err = e;
- rv = false;
- };
- installer.destroy();
-
- //install success
- if (rv) {
- this._saveRdf();
- this._obs.notifyObservers(this, "forecastfox:icons", "install");
- return true;
- };
-
- //install failed
- this._getRdf(false);
- this._manager.disk.recordError("ERROR: icon pack install error.", err);
- return false;
- },
-
- uninstallItem: function( aId )
- {
- //get the file for the pack
- var file = this._getTarget(aId, "jar");
- file = this._manager.disk.get(file, ffIDisk.TYPE_ICONS);
-
- //Create and initialize the installer.
- var installer = Components.classes["@ensolis.com/forecastfox/icon-installer;1"].createInstance(Components.interfaces.ffIIconInstaller);
- installer.init(file);
-
- //try uninstall
- var rv = false;
- try {
- rv = installer.performUninstall();
- } catch(e) {
- var err = e;
- rv = false;
- };
- installer.destroy();
-
- //uninstall success
- if (rv) {
- this._saveRdf();
- this._obs.notifyObservers(this, "forecastfox:icons", "uninstall");
- return true;
- };
-
- //install failed
- this._getRdf(false);
- this._manager.disk.recordError("ERROR: icon pack uninstall error.", err);
- return false;
- },
-
- setCurrent: function(aId)
- {
- this._current = this.getItemForId(aId);
- },
-
- _sortItems: function(a, b)
- {
- if (a.name < b.name)
- return -1;
- else
- return 1;
- },
-
- _createIconPack: function( aId )
- {
- // get the icon packs information
- var id = aId;
- var jar = this._getTarget(aId, "jar");
- var name = this._getTarget(aId, "name");
- var website = this._getTarget(aId, "website");
- var author = this._getTarget(aId, "author");
- var version = this._getTarget(aId, "version");
- var target = this._getTarget(aId, "target");
- var smallHeight = this._getTarget(aId, "smallHeight");
- var smallWidth = this._getTarget(aId, "smallWidth");
- var largeHeight = this._getTarget(aId, "largeHeight");
- var largeWidth = this._getTarget(aId, "largeWidth");
- var exemptions = [];
-
- // get resources for the id and name
- var idResource = this._rdfserv.GetResource(ICON_PREFIX + aId);
- var resource = this._rdfserv.GetResource(IM_PREFIX + "exemption");
- var els = this._ds.GetTargets(idResource, resource, true);
- while (els.hasMoreElements()) {
- var el = els.getNext().QueryInterface(Components.interfaces.nsIRDFResource);
- exemptions.push(this._createIconInfo(el));
- };
-
- // create and initialize the icon pack
- var pack = Components.classes["@ensolis.com/forecastfox/icon-pack;1"].createInstance(Components.interfaces.ffIIconPack);
- pack.init(id, jar, name, website, author, version, target, smallHeight, smallWidth, largeHeight, largeWidth, exemptions.length, exemptions);
-
- // return the pack
- return pack;
- },
-
- _createIconInfo: function( aSource )
- {
- // get the info for the exemption
- var index = this._getSourceTarget(aSource, "index");
- var size = this._getSourceTarget(aSource, "size");
- var width = this._getSourceTarget(aSource, "width");
- var height = this._getSourceTarget(aSource, "height");
-
- // create and initialize the info object
- var iconInfo = Components.classes["@ensolis.com/forecastfox/icon-info;1"].createInstance(Components.interfaces.ffIIconInfo);
- iconInfo.init("", width, height, (size == "large"), index);
-
- return iconInfo;
- },
-
- _getSourceTarget: function( aSource, aName )
- {
- // get resources for the id and name
- var nameResource = this._rdfserv.GetResource(IM_PREFIX + aName);
-
- return this._evalTarget(aSource, nameResource);
- },
-
- _getTarget: function( aId, aName )
- {
- // get resources for the id and name
- var nameResource = this._rdfserv.GetResource(IM_PREFIX + aName);
- var idResource = this._rdfserv.GetResource(ICON_PREFIX + aId);
-
- return this._evalTarget(idResource, nameResource);
- },
-
- _evalTarget: function( aSource, aProperty )
- {
- // get the target resource and then return its value
- var target = this._ds.GetTarget(aSource, aProperty, true);
- return this._getTargetValue(target);
- },
-
- _getTargetValue: function(aTarget)
- {
- if (aTarget instanceof Components.interfaces.nsIRDFLiteral)
- return aTarget.Value;
- if (aTarget instanceof Components.interfaces.nsIRDFResource)
- return aTarget.Value;
- if (aTarget instanceof Components.interfaces.nsIRDFInt)
- return aTarget.Value;
-
- return "undefined";
- },
-
- _hasIconPack: function(aId)
- {
- // get the container for all the icons
- var root = ICONS_ROOT;
- var ctr = Components.classes["@mozilla.org/rdf/container;1"].createInstance(Components.interfaces.nsIRDFContainer);
- ctr.Init(this._ds, this._rdfserv.GetResource(root));
-
- var iconNode = this._rdfserv.GetResource(ICON_PREFIX+aId);
-
- return (ctr.IndexOf(iconNode) > 0);
- },
-
- _getRdf: function(aRevert)
- {
- //unregister datasource
- if (aRevert && this._ds)
- this._rdfserv.UnregisterDataSource(this._ds);
-
- // get the datasource.rdf file
- var file = this._manager.disk.get("datasource.rdf", ffIDisk.TYPE_ICONS);
-
- // get the one from defaults if this one doesn't exist
- if (!file.exists() || aRevert) {
- this._getDefaultRdf();
- } else if (!file.isWritable() || !file.isReadable()) {
- // the file needs to be readable and writable
- this._readWriteError(file);
- this._manager.disk.recordMessage("Warning: The datasource.rdf file is not writable: "+file.path);
- return;
- } else {
- file = this._manager.disk.getFileURI(file);
- this._ds = this._rdfserv.GetDataSourceBlocking(file);
- this._verifyRdf();
- };
- },
-
- _verifyRdf: function()
- {
- try {
- var defaultPack = this.getItemForId("default");
- if (defaultPack.id != "default")
- throw "Can't get default pack from RDF datasource.";
- } catch (e) {
- this._manager.disk.recordError("ERROR: Icon datasource is corrupted.", e);
- this._manager.disk.recordFile(this._manager.disk.get("datasource.rdf", ffIDisk.TYPE_ICONS));
- this._getRdf(true);
- };
- },
-
- _getDefaultRdf: function ()
- {
- //create content string of file
- var contents = new String();
- contents += '<?xml version="1.0"?>\n' +
- '<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"\n' +
- ' xmlns:NC="http://home.netscape.com/NC-rdf#"\n' +
- ' xmlns:im="http://www.ensolis.com/2005/icon-manager#">\n' +
- ' <Seq about="urn:ensolis:icon-packs:root">\n' +
- ' </Seq>\n' +
- '</RDF>\n'
-
- //convert to dom document
- var parser = Components.classes["@mozilla.org/xmlextras/domparser;1"].createInstance(Components.interfaces.nsIDOMParser);
- var doc = parser.parseFromString(contents, "text/xml");
-
- //write to file
- var file = this._manager.disk.get("datasource.rdf", ffIDisk.TYPE_ICONS);
- this._manager.disk.write(doc, file, false);
- file = this._manager.disk.getFileURI(file);
-
- //load file as datasource
- this._ds = this._rdfserv.GetDataSourceBlocking(file);
-
- //install default icons
- var pack = this._manager.disk.get("icons", ffIDisk.TYPE_DEFAULTS);
- pack.append("default.jar");
- this.installItem(pack);
- },
-
- // Records the datasource to disk.
- _saveRdf: function()
- {
- this._ds.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource).Flush();
- },
-
- _readWriteError: function( aFile )
- {
- var alerts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
- var err_msg = this._bundle.formatStringFromName("ff.migrate.read.tooltip", [aFile.path], 1);
- var err_title = this._bundle.GetStringFromName("ff.migrate.read.label");
- alerts.alert(this._manager.getWindow(), err_title, err_msg);
- },
-
- _stripIconPrefix: function (aURI)
- {
- var prefix = ICON_PREFIX;
- var value = aURI;
-
- if (aURI.substr(0, prefix.length) == prefix)
- value = aURI.substr(prefix.length, aURI.length);
-
- return value;
- },
-
- _removeOldFiles: function()
- {
- var files = this._manager.getUTFPref("icons.uninstallfiles");
- if (files == "") return;
-
- var base = this._manager.disk.get("", ffIDisk.TYPE_ICONS);
- files = files.split(";");
-
- for (var x = 0; x < files.length; x++) {
- var file = base.clone();
- file.append(files[x]);
- if (file.exists() && file.isWritable()) {
- file.remove(false);
- };
- };
-
- this._manager.setUTFPref("icons.uninstallfiles", "");
- },
-
- ///////////////////////////
- // nsIClassInfo
- getInterfaces: function(aCount)
- {
- var ifaces = new Array();
- ifaces.push(Components.interfaces.ffIIconManager);
- ifaces.push(Components.interfaces.nsIClassInfo);
- ifaces.push(Components.interfaces.nsISupports);
- aCount.value = ifaces.length;
- return ifaces;
- },
-
- getHelperForLanguage: function(aLanguage) { return null; },
- get contractID() { return CONTRACT_ID; },
- get classID() { return CLASS_ID; },
- get classDescription() { return CLASS_NAME; },
- get implementationLanguage() { return Components.interfaces.nsIProgrammingLanguage.JAVASCRIPT; },
- get flags() { return Components.interfaces.nsIClassInfo.SINGLETON; },
-
- ///////////////////////////
- // nsISupports
- QueryInterface: function (aIID)
- {
- if (!aIID.equals(Components.interfaces.ffIIconManager) &&
- !aIID.equals(Components.interfaces.nsIClassInfo) &&
- !aIID.equals(Components.interfaces.nsISupports))
- throw Components.results.NS_ERROR_NO_INTERFACE;
- return this;
- }
- };
-
- /******************************************************************************
- * ffIIconInstaller
- ******************************************************************************/
-
- function ffIconInstaller() {};
-
- ffIconInstaller.prototype = {
-
- _manager: null,
- _file: null,
- _rdfserv: null,
- _ds: null,
- _validated: false,
- _manifest: null,
- _files: null,
- _reader: null,
- _bundle: null,
- _temp: null,
-
- get validated() { return this._validated; },
-
- init: function( aFile )
- {
- // Get services...
- this._manager = Components.classes["@ensolis.com/forecastfox/manager;1"].getService(Components.interfaces.ffIManager);
- this._rdfserv = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService);
- var sbs = Components.classes["@mozilla.org/intl/stringbundle;1"].getService(Components.interfaces.nsIStringBundleService);
- this._bundle = sbs.createBundle("chrome://forecastfox/locale/forecastfox.properties");
- this._ctrutils = Components.classes["@mozilla.org/rdf/container-utils;1"].createInstance(Components.interfaces.nsIRDFContainerUtils);
-
- // Record parameters...
- this._file = aFile.clone();
- this._ds = this._manager.icons.datasource;
- this._files = [];
-
- // Prepare the nsIZipReader...
- this._reader = Components.classes["@mozilla.org/libjar/zip-reader;1"].createInstance(Components.interfaces.nsIZipReader);
- this._reader.init(this._file);
- this._reader.open();
-
- // Get a list of all the files...
- this._populateFileList();
- },
-
- destroy: function()
- {
- this._reader.close();
-
- try {
- if (this._temp)
- this._temp.remove(false);
- } catch(e) {};
-
- this._manager = null;
- this._bundle = null;
- this._rdfserv = null;
- this._file = null;
- this._ds = null;
- this._manifest = null;
- this._files = null;
- this._reader = null;
- this._ctrutils = null;
- this._temp = null;
- },
-
- validate: function()
- {
- this._getManifest();
-
- // Throw an error if there is no manifest.
- if (!this._validateManifest())
- return this._createError(ffIError.SEVERITY_ERROR, null, "ff.icons.manifest");
-
- // Make sure we have all the required files.
- var err = this._validateRequiredFiles();
- if (err.severity != ffIError.SEVERITY_INFO)
- return err;
-
- // Mark as validated so that the install can be executed.
- this._validated = true;
-
- // Return a SEVERITY_INFO since the jar is good (the message won't be displayed).
- return this._createError(ffIError.SEVERITY_INFO, "all good");
- },
-
- performInstall: function()
- {
- // You must validate before performing an install.
- if (!this._validated)
- return false;
-
- this._getId();
-
- // Copy the icon pack jar to the correct location.
- if (!this._copyPack())
- return false;
-
- // Register the icon pack in the rdf datasource.
- return this._registerPack();
- },
-
- performUninstall: function()
- {
- // Initialize the icon pack container in the main datasource.
- var ctr = Components.classes["@mozilla.org/rdf/container;1"].createInstance(Components.interfaces.nsIRDFContainer);
- ctr.Init(this._ds, this._rdfserv.GetResource(ICONS_ROOT));
-
- //get the id of the pack
- this._getManifest();
- this._getId();
-
- //unregister the pack.
- var id = this._rdfserv.GetResource(ICON_PREFIX + this._id);
- if (ctr.IndexOf(id) >= 0)
- this._unregisterPack(id, ctr);
- else
- return false;
-
- //success
- return true;
- },
-
- // Gets and returns the datasource representing the file object that is in the
- _getManifest: function()
- {
- // Verify that we have a pack.rdf in the icon pack.
- if (!this._hasFile("pack.rdf"))
- this._manifest = false;
-
- // Get a temp file to store the pack.rdf in.
- this._temp = this._manager.disk.get("icon-pack.rdf", ffIDisk.TYPE_TEMP);
-
- // Extract the file and get the datasource object for it...
- this._reader.extract("pack.rdf", this._temp);
- this._manifest = this._rdfserv.GetDataSourceBlocking(this._manager.disk.getFileURI(this._temp));
- },
-
- _validateManifest: function()
- {
- // Fail if there is no manifest.
- if (!this._manifest)
- return false;
-
- var source = this._rdfserv.GetResource(ICON_PREFIX+"install");
-
- // Check for the required properties...
- for (var x = 0; x < REQUIRED_ICON_PROPS.length; x++) {
- var resource = this._rdfserv.GetResource(IM_PREFIX + REQUIRED_ICON_PROPS[x]);
- if (!this._manifest.hasArcOut(source, resource)) {
- return false;
- };
- };
-
- return true;
- },
-
- _validateRequiredFiles: function()
- {
- var required = REQUIRED_PACK_FILES;
-
- // Make sure every required file can be found in the icon pack.
- for (var x = 0; x < required.length; x++) {
- var found = false;
- for (var y = 0; y < this._files.length; y++) {
- if (required[x] == this._files[y]) {
- found = true;
- break;
- };
- };
-
- // Don't return an error if the file has been found.
- if (found) continue;
-
- return this._createError(ffIError.SEVERITY_ERROR, this._getFileString(required[x]));
- };
-
- // All files present...
- return this._createError(ffIError.SEVERITY_INFO, "required files are present"); // message not displayed
- },
-
- _copyPack: function()
- {
- // remove ";" characters from name so that the uninstall works
- var file = this._manager.disk.get(this._id.replace(";", "") + ".jar", ffIDisk.TYPE_ICONS);
-
- file.createUnique(nsIFile.NORMAL_FILE_TYPE, 0664);
-
- this._jar = file.leafName;
-
- this._manager.disk.copy(this._file, file);
-
- return true;
- },
-
- _registerPack: function()
- {
- // Initialize the icon pack container in the main datasource.
- var ctr = Components.classes["@mozilla.org/rdf/container;1"].createInstance(Components.interfaces.nsIRDFContainer);
- ctr.Init(this._ds, this._rdfserv.GetResource(ICONS_ROOT));
-
- // If it is an upgrade, first unregister the old pack.
- var id = this._rdfserv.GetResource(ICON_PREFIX + this._id);
- if (ctr.IndexOf(id) >= 0)
- this._unregisterPack(id, ctr);
-
- // Insert the new node.
- ctr.AppendElement(id);
- var jar = this._rdfserv.GetResource(IM_PREFIX + "jar");
- var jarlit = this._rdfserv.GetLiteral(this._jar);
- this._ds.Assert(id, jar, jarlit, true);
-
-
- // Copy the required properties.
- var source = this._rdfserv.GetResource(ICON_PREFIX + "install");
- for (var i=0; i<REQUIRED_ICON_PROPS.length; ++i) {
- var resource = this._rdfserv.GetResource(IM_PREFIX + REQUIRED_ICON_PROPS[i]);
- this._setProperty(id, source, resource);
- };
-
- // Copy the optional properties
- var index = this._rdfserv.GetResource(IM_PREFIX + "index");
- var size = this._rdfserv.GetResource(IM_PREFIX + "size");
- var width = this._rdfserv.GetResource(IM_PREFIX + "width");
- var height = this._rdfserv.GetResource(IM_PREFIX + "height");
- var resource = this._rdfserv.GetResource(IM_PREFIX + "exemption");
- var els = this._manifest.GetTargets(source, resource, true);
- while (els.hasMoreElements()) {
- var el = els.getNext().QueryInterface(Components.interfaces.nsIRDFResource);
- var anon = this._rdfserv.GetAnonymousResource();
- this._ds.Assert(anon, index, this._manifest.GetTarget(el, index, true), true);
- this._ds.Assert(anon, size, this._manifest.GetTarget(el, size, true), true);
- this._ds.Assert(anon, width, this._manifest.GetTarget(el, width, true), true);
- this._ds.Assert(anon, height, this._manifest.GetTarget(el, height, true), true);
- this._ds.Assert(id, resource, anon, true);
- };
-
- // Success!
- return true;
- },
-
- _unregisterPack: function(aIdResource, aContainer)
- {
- //remove jar
- var jar = this._rdfserv.GetResource(IM_PREFIX + "jar");
- jar = this._ds.GetTarget(aIdResource, jar, true);
- jar = jar.QueryInterface(Components.interfaces.nsIRDFLiteral);
- jar = this._manager.disk.get(jar.Value, ffIDisk.TYPE_ICONS);
- if (jar.exists())
- this._delayRemove(jar);
-
- //remove exemptions
- var els = this._ds.GetTargets(aIdResource, this._rdfserv.GetResource(IM_PREFIX + "exemption"), true);
- while (els.hasMoreElements()) {
- var el = els.getNext().QueryInterface(Components.interfaces.nsIRDFResource);
- this._cleanResource(el);
- };
-
- //remove item
- this._cleanResource(aIdResource);
- aContainer.RemoveElement(aIdResource, true);
- },
-
- _delayRemove: function ( /* nsIFile */ aFile )
- {
- var file = aFile.leafName;
- var files = this._manager.getUTFPref("icons.uninstallfiles");
-
- // want: file1.jar or file1.jar;file2.jar;file3.jar
- files = ((files != "") ? files + ";" : "") + file;
-
- this._manager.setUTFPref("icons.uninstallfiles", files);
- },
-
- _cleanResource: function(aIdResource)
- {
- // Remove outward arcs
- var arcs = this._ds.ArcLabelsOut(aIdResource);
- while (arcs.hasMoreElements()) {
- var arc = arcs.getNext().QueryInterface(Components.interfaces.nsIRDFResource);
- var targets = this._ds.GetTargets(aIdResource, arc, true);
- while (targets.hasMoreElements()) {
- var value = targets.getNext().QueryInterface(Components.interfaces.nsIRDFNode);
- if (value)
- this._ds.Unassert(aIdResource, arc, value);
- };
- };
- },
-
- _setProperty: function( aNode, aSource, aTarget )
- {
- var value = this._manifest.GetTarget(aSource, aTarget, true);
- this._ds.Assert(aNode, aTarget, value, true);
- },
-
- _populateFileList: function()
- {
- var entries = this._reader.findEntries("*");
-
- while (entries.hasMoreElements()) {
- var entry = entries.getNext().QueryInterface(Components.interfaces.nsIZipEntry);
- this._files.push(entry.name);
- };
- },
-
- _hasFile: function( aFileName )
- {
- for (var x = 0; x < this._files.length; x++) {
- if (this._files[x] == aFileName)
- return true;
- };
-
- return false;
- },
-
- _createError: function( aSeverity, aDescription, aString )
- {
- var description = (aDescription) ? aDescription : this._bundle.GetStringFromName(aString);
- var title = this._bundle.GetStringFromName("ff.icons.invalid");
- var error = Components.classes["@ensolis.com/forecastfox/error;1"].createInstance(Components.interfaces.ffIError);
- error.init(aSeverity, "@ensolis.com/forecastfox/profiles;1", description, title);
- return error;
- },
-
- _getFileString: function( aFile )
- {
- return this._bundle.formatStringFromName("ff.icons.file", [aFile], 1);
- },
-
- _getId: function()
- {
- var source = this._rdfserv.GetResource(ICON_PREFIX + "install");
- var id = this._rdfserv.GetResource(IM_PREFIX + "id");
- id = this._manifest.GetTarget(source, id, true);
- id = id.QueryInterface(Components.interfaces.nsIRDFLiteral);
- this._id = id.Value;
- },
-
- ///////////////////////////
- // nsIClassInfo
- getInterfaces: function(aCount)
- {
- var ifaces = new Array();
- ifaces.push(Components.interfaces.ffIIconInstaller);
- ifaces.push(Components.interfaces.nsIClassInfo);
- ifaces.push(Components.interfaces.nsISupports);
- aCount.value = ifaces.length;
- return ifaces;
- },
-
- getHelperForLanguage: function(aLanguage) { return null; },
- get contractID() { return INSTALLER_CONTRACT_ID; },
- get classID() { return INSTALLER_CLASS_ID; },
- get classDescription() { return INSTALLER_CLASS_NAME; },
- get implementationLanguage() { return Components.interfaces.nsIProgrammingLanguage.JAVASCRIPT; },
- get flags() { return Components.interfaces.nsIClassInfo.THREADSAFE; },
-
- ///////////////////////////
- // nsISupports
- QueryInterface: function (aIID)
- {
- if (!aIID.equals(Components.interfaces.ffIIconInstaller) &&
- !aIID.equals(Components.interfaces.nsIClassInfo) &&
- !aIID.equals(Components.interfaces.nsISupports))
- throw Components.results.NS_ERROR_NO_INTERFACE;
- return this;
- }
- };
-
- /******************************************************************************
- * XPCOM Functions for construction and registration
- ******************************************************************************/
- var gModule = {
- _firstTime: true,
- _objects: {
- iconManager: {
- CID: MANAGER_CLASS_ID,
- contractID: MANAGER_CONTRACT_ID,
- className: MANAGER_CLASS_NAME,
- factory: {
- createInstance: function (aOuter, aIID)
- {
- if (aOuter != null)
- throw Components.results.NS_ERROR_NO_AGGREGATION;
- return (new ffIconManager()).QueryInterface(aIID);
- }
- }
- },
-
- iconInstaller: {
- CID: INSTALLER_CLASS_ID,
- contractID: INSTALLER_CONTRACT_ID,
- className: INSTALLER_CLASS_NAME,
- factory: {
- createInstance: function (aOuter, aIID)
- {
- if (aOuter != null)
- throw Components.results.NS_ERROR_NO_AGGREGATION;
- return (new ffIconInstaller()).QueryInterface(aIID);
- }
- }
- }
- },
-
- registerSelf: function(aCompMgr, aFileSpec, aLocation, aType)
- {
- if (this._firstTime) {
- this._firstTime = false;
- throw Components.results.NS_ERROR_FACTORY_REGISTER_AGAIN;
- };
- aCompMgr = aCompMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
- for (var key in this._objects) {
- var obj = this._objects[key];
- aCompMgr.registerFactoryLocation(obj.CID, obj.className, obj.contractID,
- aFileSpec, aLocation, aType);
- };
- },
-
- unregisterSelf: function(aCompMgr, aLocation, aType)
- {
- aCompMgr = aCompMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
- for (var key in this._objects) {
- var obj = this._objects[key];
- aCompMgr.unregisterFactoryLocation(obj.CID, aLocation);
- };
- },
-
- getClassObject: function(aCompMgr, aCID, aIID)
- {
- if (!aIID.equals(Components.interfaces.nsIFactory))
- throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
-
- for (var key in this._objects) {
- if (aCID.equals(this._objects[key].CID))
- return this._objects[key].factory;
- };
-
- throw Components.results.NS_ERROR_NO_INTERFACE;
- },
-
- canUnload: function(aCompMgr) { return true; }
- };
-
- var gFactory = {
- createInstance: function (aOuter, aIID)
- {
- if (aOuter != null)
- throw Components.results.NS_ERROR_NO_AGGREGATION;
- return (new ffIconManager()).QueryInterface(aIID);
- }
- };
-
- function NSGetModule(aCompMgr, aFileSpec) { return gModule; }